// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FillStyle.java

package com.java4less.rchart;

import com.java4less.rchart.gc.ChartColor;
import com.java4less.rchart.gc.ChartGraphics;
import com.java4less.rchart.gc.ChartImage;
import com.java4less.rchart.gc.GraphicsProvider;

// Referenced classes of package com.java4less.rchart:
//			ChartLoader

public class FillStyle
{

	public static int NO_GRADIENT = 0;
	public static int GRADIENT_HORIZONTAL = 1;
	public static int GRADIENT_VERTICAL = 2;
	public Object fillPatern;
	public float alphaValue;
	private Object composite;
	ChartColor color;
	public ChartColor colorFrom;
	public ChartColor colorUntil;
	public int gradientType;
	public boolean gradientCyclic;
	public ChartImage textureImage;

	public FillStyle(ChartColor c)
	{
		fillPatern = null;
		alphaValue = 1.0F;
		composite = null;
		colorFrom = GraphicsProvider.getColor(ChartColor.RED);
		colorUntil = GraphicsProvider.getColor(ChartColor.WHITE);
		gradientType = NO_GRADIENT;
		gradientCyclic = false;
		textureImage = null;
		color = c;
	}

	public FillStyle(ChartImage i)
	{
		fillPatern = null;
		alphaValue = 1.0F;
		composite = null;
		colorFrom = GraphicsProvider.getColor(ChartColor.RED);
		colorUntil = GraphicsProvider.getColor(ChartColor.WHITE);
		gradientType = NO_GRADIENT;
		gradientCyclic = false;
		textureImage = null;
		textureImage = i;
		color = GraphicsProvider.getColor(ChartColor.WHITE);
	}

	public FillStyle(ChartColor c, float f)
	{
		fillPatern = null;
		alphaValue = 1.0F;
		composite = null;
		colorFrom = GraphicsProvider.getColor(ChartColor.RED);
		colorUntil = GraphicsProvider.getColor(ChartColor.WHITE);
		gradientType = NO_GRADIENT;
		gradientCyclic = false;
		textureImage = null;
		color = c;
		alphaValue = f;
	}

	public String toString()
	{
		if (gradientType != NO_GRADIENT)
			return (new StringBuilder()).append(colorFrom.getRGBString()).append(";").append(colorUntil.getRGBString()).toString();
		if (alphaValue != 1.0F)
			return (new StringBuilder()).append(color.getRGBString()).append("|").append(alphaValue).toString();
		else
			return color.getRGBString();
	}

	public static FillStyle createFromString(String f)
	{
		String items[];
		ChartColor c;
		if (f.toUpperCase().indexOf(".JPEG") > 0 || f.toUpperCase().indexOf(".JPG") > 0 || f.toUpperCase().indexOf(".PNG") > 0 || f.toUpperCase().indexOf(".GIF") > 0)
		{
			ChartImage image = GraphicsProvider.getImageFromFile(f);
			return new FillStyle(image);
		}
		int p = f.indexOf(";");
		String separator = ";";
		if (p == -1)
		{
			p = f.indexOf(":");
			separator = ":";
		}
		if (p > -1)
		{
			items = ChartLoader.convertList(f, separator);
			FillStyle fillFrom = new FillStyle(GraphicsProvider.getColor(ChartColor.BLACK));
			fillFrom.colorFrom = ChartLoader.convertColor(items[0]);
			fillFrom.color = fillFrom.colorFrom;
			fillFrom.colorUntil = ChartLoader.convertColor(items[1]);
			fillFrom.gradientType = GRADIENT_VERTICAL;
			if (items.length > 2 && items[2].toUpperCase().compareTo("HORIZONTAL") == 0)
				fillFrom.gradientType = GRADIENT_HORIZONTAL;
			return fillFrom;
		}
		if (f.compareTo("") == 0)
			return null;
		items = ChartLoader.convertList(f);
		if (items == null)
			return null;
		if (items.length < 1)
			return null;
		c = ChartLoader.convertColor(items[0]);
		if (items.length == 1)
			return new FillStyle(c);
		return new FillStyle(c, (new Float(items[1])).floatValue());
		Exception e;
		e;
		e.printStackTrace();
		return null;
	}

	public ChartColor getColor()
	{
		return color;
	}

	protected void drawArc(ChartGraphics g, int x, int y, int w, int h, int a1, int a2)
	{
		g.setTexture(textureImage);
		g.setColor(color);
		setAlpha(g);
		g.fillArc(x, y, w, h, a1, a2);
		resetAlpha(g);
	}

	private void setAlpha(ChartGraphics g)
	{
		if (alphaValue != 1.0F)
		{
			composite = g.getAlphaComposite();
			g.setAlpha(alphaValue);
		}
	}

	private void resetAlpha(ChartGraphics g)
	{
		if (composite != null)
			g.setAlphaComposite(composite);
		composite = null;
	}

	protected void drawPolygon(ChartGraphics g, int x1[], int y1[], int num)
	{
		g.setTexture(textureImage);
		g.setColor(color);
		setAlpha(g);
		g.fillPolygon(x1, y1, num);
		resetAlpha(g);
	}

	protected void draw(ChartGraphics g, int x1, int y1, int x2, int y2)
	{
		if (x1 > x2)
		{
			int xtmp = x2;
			x2 = x1;
			x1 = xtmp;
		}
		if (y1 > y2)
		{
			int ytmp = y2;
			y2 = y1;
			y1 = ytmp;
		}
		g.setTexture(textureImage);
		g.setColor(color);
		if (gradientType != NO_GRADIENT)
		{
			g.createFadeArea(colorFrom, colorUntil, x1, y1, x2 - x1, y2 - y1, gradientType == GRADIENT_VERTICAL, gradientCyclic);
		} else
		{
			setAlpha(g);
			g.fillRect(x1, y1, x2 - x1, y2 - y1);
			resetAlpha(g);
		}
	}

	public void drawRoundRect(ChartGraphics g, int x1, int y1, int x2, int y2)
	{
		g.setTexture(textureImage);
		g.setColor(color);
		setAlpha(g);
		g.fillRoundRect(x1, y1, x2 - x1, y2 - y1);
		resetAlpha(g);
	}

}
